package com.fjt.book_trade.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fjt.book_trade.pojo.User;

public interface IUserDao {
	@Results({
		@Result(property = "username", column = "username"),
		@Result(property = "password", column = "password"),
		@Result(property = "email", column = "email"),
		@Result(property = "address", column = "address"),
		@Result(property = "phonenumber", column = "phonenumber"),
		@Result(property = "paynumber", column = "paynumber"),
		@Result(property = "type", column = "type"),
		@Result(property = "payname", column = "payname")}
	)
	
	@Select("Select * from user where username=#{username}")
	public User findUserInfoByName(String username);
	
	@Select("Select * from user where username=#{username} and password=#{password}")
	public User validateUser(User user);
	
	@Insert("Insert into user VALUES(#{username}, #{password},#{email},#{address},#{phonenumber},#{type},#{payname})")
	public boolean addUser(User user);
	
	@Update("update user set password=#{newpwd} where username=#{username} and password=#{oldpwd}")
	public boolean modifyPassword(User user);
	
	@Update("update user set address=#{address},phonenumber=#{phonenumber},type=#{type},payname=#{payname} "
			+ "where username=#{username} and password=#{oldpwd}")
	public boolean modifyUserInfo(@Param("username") String username,@Param("oldpwd") String oldpwd,
			@Param("address") String address,@Param("phonenumber") String phonenumber,
			@Param("type") boolean type,@Param("payname") String payname);
	
	
	//	public boolean validate(User user);
//	public User findUserByEmail(String email);
//	public void modifyPassword(User user);
}
